﻿
//切换tab刷新数据
function changeTab(tab) {
    //console.log(tab)
    var group = "";
    $(".sales_group").each(function () {
        if ($(this).attr("class").indexOf("group_active") > -1) {
            group += $(this).attr("data-group");
        }
    })

    loadSales(group);
}


//销售排行数据
function loadSales(group) {
    //天数
    var days = 0;
    $(".group_days").each(function () {
        if ($(this).attr("class").indexOf("color_y") > -1) {
            days = $(this).attr("data-days");
        }
    })
    // 百分比
    var min = 0, max = 0;
    $(".group_scale").each(function () {
        if ($(this).attr("class").indexOf("color_y") > -1) {
            min = $(this).attr("data-min");
            max = $(this).attr("data-max");
        }
    })

    var param = "";
    if (group == 1 || group == 2) {
        param = "staffId=" + staffId + "&groups=" + group + "&days=" + days;
    }
    if (group == 3 || group == 4) {
        param = "staffId=" + staffId + "&groups=" + group + "&days=" + days;
    }

    if (group == 5) {
        param = "staffId=" + staffId + "&groups=" + group + "&min=" + min + "&max=" + max;
    }

    ajaxGet(siteApiList.GetSalesList + "?" + param, function (data) {
        if (!isJsonSuccess(data))
            return;
        if (data.Data == null) return;

        //绑定列表数据
        var html = ""
        var html2 = "";
        var list = data.Data;
        //第一名//../images/boss/33.png
        if (list.Avater == null)
            list.Avater = "../images/boss/33.png";
        html = " <div class='sort_left'><ul><li class='number number_active'>1</li><li class='userimg'><img src='" + siteConfig.formatAvater(list[0].Avater) + "' alt=''></li><li class='name f16'>" + list[0].Name + "</li></ul></div><div class='sort_right'><span class='f25'>" + list[0].Counts + "</span></div></div>";
        $('#top-box').html("");
        $('#top-box').append(html);
        //其他;
        for (var i = 0; i < list.length; i++) {
            if (i == 0)
                html2 += "<div class='sort_content'><div class='sort_box'><div class='sort_left'><ul><li class='number number_active'>" + parseInt(i + 1) + "</li><li class='userimg number_one'><img id='onetop' src='../images/boss/33.png' alt=''><img src='" + siteConfig.formatAvater(list[i].Avater) + "' alt=''></li><li class='name number_active f16'>" + list[i].Name + "</li></ul></div><div class='sort_right'><span class='f25'>" + list[i].Counts + "</span></div></div></div>";
            else {
                html2 += "<div class='sort_content'><div class='sort_box'><div class='sort_left'><ul><li class='number number_active'>" + parseInt(i + 1) + "</li><li class='userimg number_one'><img src='" + siteConfig.formatAvater(list[i].Avater) + "' alt=''></li><li class='name number_active f16'>" + list[i].Name + "</li></ul></div><div class='sort_right'><span class='f25'>" + list[i].Counts + "</span></div></div></div>";
            }
        }
        $('#bottom-box').html("");
        $('#bottom-box').append(html2);
    })
}